<template>
  <div style="width: 100%;height:100%">
    <a-form-model
      :model="form"
      class="AsteriskAfter newEditStyle rightDrawerWithoutCol"
      :rules="rules"
      :colon="false"
      ref="validateForm">
      <!-- 测试结论 -->
      <a-form-model-item :label="$t('testConclusion')" class="formItemForMargin" prop="engTestVerdict">
          <a-select v-model="form.engTestVerdict">
           <a-select-option
             v-for="item in passOrNot"
             :key="item.value"
             >{{ item.name }}</a-select-option>
           </a-select>
      </a-form-model-item>
      <!-- 测试总结 -->
      <a-form-model-item :label="$t('testSummary')" class="formItemForMargin">
        <custom-text-area @change="form.engTestSummary = $event" :val="form.engTestSummary" :max-len="2000"></custom-text-area>
      </a-form-model-item>
      <!-- 适用车型配置 -->
      <a-form-model-item :label="$t('suitableVehicleConfig')" class="formItemForMargin" prop="modelConfigure">
        <a-input v-model="form.modelConfigure"/>
      </a-form-model-item>
       <!-- 内部受控 -->
      <a-form-model-item :label="$t('internalControl')" class="formItemForMargin" prop="controlled">
          <a-select v-model="form.controlled">
           <a-select-option
             v-for="item in yesOrNoEnumArr"
             :key="item.value"
             >{{ item.name }}</a-select-option>
           </a-select>
      </a-form-model-item>
    </a-form-model>
  </div>
  <!-- </custom-modal> -->
</template>
<script>
import { checkTextLen } from '@/utils/validate'
import CustomModal from '@/components/CustomModal/index.vue'
import CustomTextArea from '@/components/CustomTextArea/index.vue'
import { passOrNot,yesOrNoEnumArr } from '../config/list'
export default {
  name: 'AddAuditInfo',
  components: {
    CustomModal,
    CustomTextArea
  },
  props: {
    formData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      modalVisibal: false,
      passOrNot,
      yesOrNoEnumArr,
      flowOptions: [],
     
      form: {
        engTestSummary: '',
        engTestVerdict: '',
        modelConfigure: '',
        controlled: '',
        id:this.$route.query.key
      },
      action: 'add',
      rules: {
        engTestVerdict: [{ required: true, message: this.$t('pleaseSelect') }],
        controlled: [{ required: true, message: this.$t('pleaseSelect') }],
        modelConfigure: [{ required: true, message: this.$t('pleaseInput')},{ validator: checkTextLen(1000, true)}],
      },
      isSearch: false
    }
  },

  methods: {
    // 获取表单中的数据
    getFormData () {
      return new Promise((resolve, reject) => {
        if (this.action === 'add') {
          this.$refs.validateForm.validate(valid => {
            if (!valid) {
              reject(valid)
              return 
            }
            resolve(this.form)
          })
        }
      })
    },
    // 对话框点击保存
    handleOk () {
      if (this.action === 'add') {
        const vm = this
        this.$refs.validateForm.validate((res) => {
          if (res) {
            vm.$api
              .addTestInfoDetail(vm.form)
              .finally(() => {
                vm.modalVisibal = false
                this.$message.success(this.$t('successfullyOperation'))
                vm.resetData()
                vm.$emit('addOrEditDone', true)
              })
          }
        })
      } 
    },
    // 对话框点击取消
    handleCancel () {
      this.resetData()
      this.modalVisibal = false
    },
    // 手动重置数据
    resetData () {
      this.form.engTestSummary = ''
      this.form.engTestVerdict = ''
      this.form.controlled = ''
      this.form.modelConfigure = ''
    }
  }
}
</script>
<style lang="less" scoped>
.formWrap {
  margin-top: 20px;
  margin-bottom: 60px;
  .formItemForMargin {
    margin-bottom: 40px;
  }
}
</style>
